home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / ifcico / flaglex.l < prev    next >
Encoding:
Lex Description  |  1994-04-23  |  5.0 KB  |  205 lines

  1. %{
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "ftn.h"
  5. #include "lutil.h"
  6. #include "nodelist.h"
  7.  
  8. static char *yyPTR = NULL;
  9. static int yyBUFL;
  10.  
  11. #ifndef yywrap
  12. #define yywrap() 1
  13. #endif
  14.  
  15. #ifdef FLEX_SCANNER
  16.  
  17. #undef YY_INPUT
  18. #define YY_INPUT(buf,result,max_size) \
  19.     if ((yyPTR == NULL) || (*yyPTR == '\0')) \
  20.     { \
  21.         debug(13,"YY_INPUT unavail, %d reqd",max_size); \
  22.         result=YY_NULL; \
  23.     } \
  24.     else \
  25.     { \
  26.         yyBUFL=strlen(yyPTR); \
  27.         debug(13,"YY_INPUT \"%s\" (%d) avail, %d reqd",\
  28.             yyPTR,yyBUFL,max_size); \
  29.         if (yyBUFL > max_size) yyBUFL=max_size; \
  30.         memcpy(buf,yyPTR,yyBUFL); \
  31.         yyPTR += yyBUFL; \
  32.         result=yyBUFL; \
  33.     }
  34.  
  35. #else /* this is most probably native lex? */
  36.  
  37. #undef input
  38. #undef output
  39. #undef unput
  40.  
  41. #define input() (((yyPTR == NULL) || (*yyPTR == '\0'))?NULL:*yyPTR++)
  42. #define output(c)
  43. #define unput(c) (*--yyPTR = (c))
  44.  
  45. #endif
  46.  
  47. int flagfor(char *);
  48. int chkaddr(char*);
  49. int chktime(char*);
  50. int yylval;
  51. %}
  52.  
  53. Blank        [ \t\n]+
  54. Speed        [Ss][Pp][Ee][Ee][Dd]
  55. Phone        [Pp][Hh][Oo][Nn][Ee]
  56. Time        [Tt][Ii][Mm][Ee]
  57. Address        [Aa][Dd][Dd][Rr][Ee][Ss][Ss]
  58. Sun        [Ss][Uu][Nn]
  59. Mon        [Mm][Oo][Nn]
  60. Tue        [Tt][Uu][Ee]
  61. Wed        [Ww][Ee][Dd]
  62. Thu        [Tt][Hh][Uu]
  63. Fri        [Ff][Rr][Ii]
  64. Sat        [Ss][Aa][Tt]
  65. Any        [Aa][Nn][Yy]
  66. Wk        [Ww][Kk]
  67. We        [Ww][Ee]
  68. Eq        ==
  69. Ne        !=
  70. Gt        \>
  71. Ge        \>=
  72. Lt        \<
  73. Le        \<=
  74. And        \&
  75. Or        \|
  76. Not        \!
  77. Xor        [Xx][Oo][Rr]
  78. Lb        \(
  79. Rb        \)
  80. Comma        \,
  81. Asterisk    \*
  82. Dow        ({Sun}|{Mon}|{Tue}|{Wed}|{Thu}|{Fri}|{Sat}|{Any}|{Wk}|{We})
  83. Hour        (([0-1][0-9])|(2[0-3]))
  84. Minute        [0-5][0-9]
  85. Decimal        [1-9][0-9]*
  86. Phstr        [0-9-]*-[0-9-]*
  87. Ident        [A-Za-z][A-Za-z0-9]*
  88. Timestr        {Dow}({Hour}{Minute}\-{Hour}{Minute})?
  89. Addrstr        (({Decimal}|\*):)?({Decimal}|\*)\/({Decimal}|\*)(.({Decimal}|\*))?(@({Ident}|\*))?
  90. %%
  91. {Blank}        ;
  92. {Decimal}    {debug(13,"Decimal: \"%s\"",yytext);yylval=strtol(yytext,NULL,0);return(NUMBER);}
  93. {Timestr}    {debug(13,"Timestr: \"%s\"",yytext);yylval=chktime(yytext);return(TIMESTR);}
  94. {Phstr}        {debug(13,"Phstr: \"%s\"",yytext);yylval=PHSTR;return(PHSTR);}
  95. {Eq}        {yylval=EQ;return(AROP);}
  96. {Ne}        {yylval=NE;return(AROP);}
  97. {Gt}        {yylval=GT;return(AROP);}
  98. {Ge}        {yylval=GE;return(AROP);}
  99. {Lt}        {yylval=LT;return(AROP);}
  100. {Le}        {yylval=LE;return(AROP);}
  101. {And}        {yylval=AND;return(LOGOP);}
  102. {Or}        {yylval=OR;return(LOGOP);}
  103. {Not}        {yylval=NOT;return(NOT);}
  104. {Xor}        {yylval=XOR;return(LOGOP);}
  105. {Lb}        {yylval=LB;return(LB);}
  106. {Rb}        {yylval=RB;return(RB);}
  107. {Comma}        {yylval=COMMA;return(COMMA);}
  108. {Asterisk}    {yylval=ASTERISK;return(ASTERISK);}
  109. {Speed}        {yylval=SPEED;return(SPEED);}
  110. {Phone}        {yylval=PHONE;return(PHONE);}
  111. {Time}        {yylval=TIME;return(TIME);}
  112. {Address}    {yylval=ADDRESS;return(ADDRESS);}
  113. {Ident}        {debug(13,"Ident: \"%s\"",yytext);yylval=flagfor(yytext);return(IDENT);}
  114. {Addrstr}    {debug(13,"Addrstr: \"%s\"",yytext);yylval=chkaddr(yytext);return(ADDRSTR);}
  115. %%
  116.  
  117. int flagfor(str)
  118. char *str;
  119. {
  120.     int i;
  121.  
  122.     debug(13,"flagfor \"%s\"",str);
  123.     for (i=0;fkey[i].key;i++)
  124.         if (strcasecmp(str,fkey[i].key) == 0) return fkey[i].flag;
  125.     return -1;
  126. }
  127.  
  128. int chkaddr(str)
  129. char *str;
  130. {
  131.     faddr *addr;
  132.     int rc=1;
  133.  
  134.     if ((addr=parsefnode(str)) == NULL)
  135.     {
  136.         logerr("unparsable address \"%s\" in expression",str);
  137.         return 0;
  138.     }
  139.     debug(13,"chkaddr: does spec %s match remote address ?",
  140.         ascfnode(addr,0x1f));
  141.     if ((addr->domain) && (nodebuf->addr.domain) && 
  142.         (strcasecmp(addr->domain,nodebuf->addr.domain) != 0))
  143.         rc=0;
  144.     if (((int)addr->zone > 0) && (addr->zone != nodebuf->addr.zone)) rc=0;
  145.     if (((int)addr->net > 0) && (addr->net != nodebuf->addr.net)) rc=0;
  146.     if (((int)addr->node > 0) && (addr->node != nodebuf->addr.node)) rc=0;
  147.     if (((int)addr->point > 0) && (addr->point != nodebuf->addr.point)) rc=0;
  148.     tidy_faddr(addr);
  149.     return rc;
  150. }
  151.  
  152. int chktime(str)
  153. char *str;
  154. {
  155.     int h1,h2,m1,m2,beg,end,cur,dayok,day;
  156.  
  157.     if (strncasecmp(str,"Sun",3) == 0) day=0;
  158.     else if (strncasecmp(str,"Mon",3) == 0) day=1;
  159.     else if (strncasecmp(str,"Tue",3) == 0) day=2;
  160.     else if (strncasecmp(str,"Wed",3) == 0) day=3;
  161.     else if (strncasecmp(str,"Thu",3) == 0) day=4;
  162.     else if (strncasecmp(str,"Fri",3) == 0) day=5;
  163.     else if (strncasecmp(str,"Sat",3) == 0) day=6;
  164.     else if (strncasecmp(str,"Any",3) == 0) day=-1;
  165.     else if (strncasecmp(str,"Wk",2) == 0) day=-2;
  166.     else if (strncasecmp(str,"We",2) == 0) day=-3;
  167.     else day=-4;
  168.  
  169.     debug(13,"chkday: does day %d match spec %d ?",now->tm_wday,day);
  170.     if (day >= 0) dayok=(now->tm_wday == day);
  171.     else switch (day)
  172.     {
  173.     case -3: dayok=((now->tm_wday == 0) || (now->tm_wday == 6)); break;
  174.     case -2: dayok=((now->tm_wday != 0) && (now->tm_wday != 6)); break;
  175.     case -1: dayok=1; break;
  176.     default: logerr("internal error: chkday got %d",day); dayok=0; break;
  177.     }
  178.  
  179.     if (dayok == 0) return 0;
  180.  
  181.     while (*str && ((*str < '0') || (*str > '9'))) str++;
  182.     if (*str == '\0')
  183.     {
  184.         return 1;
  185.     }
  186.     if (sscanf(str,"%02d%02d-%02d%02d",&h1,&m1,&h2,&m2) != 4)
  187.     {
  188.         logerr("invalid time string \"%s\" in expression",str);
  189.         return 0;
  190.     }
  191.     debug(13,"chktime: is %02d:%02d between %02d:%02d and %02d:%02d ?",
  192.         now->tm_hour,now->tm_min,h1,m1,h2,m2);
  193.     cur=now->tm_hour*60+now->tm_min;
  194.     beg=h1*60+m1;
  195.     end=h2*60+m2;
  196.     if (end > beg)
  197.     {
  198.         return ((cur >= beg) && (cur <= end));
  199.     }
  200.     else
  201.     {
  202.         return ((cur >= beg) || (cur <= end));
  203.     }
  204. }
  205.